/**
 * 除法(处理小数运算精度问题)
 * 0.0001 / 0.05 === ((0.0001*10000) / (5*100)) * (100 / 10000) === (1 / 5) * (Math.pow(10,2) / Math.pow(10,4))
 * @param {String | Number} divisor 除数
 * @param {String | Number} dividend 被除数
 * @return {Number}
*/
function divide(divisor, dividend) {
  const divisorNum = Number(divisor) || 0
  const dividendNum = Number(dividend) || 0
  const divisorStr = divisorNum.toString()
  const dividendStr = dividendNum.toString()
  const divisorPrecision = divisorStr.split('.')[1]?.length || 0
  const dividendPrecision = dividendStr.split('.')[1]?.length || 0

  // 获取整数之商, 倍率反比
  const intQuot = divisorStr.replace('.', '') / dividendStr.replace('.', '')
  const inverseRatio = Math.pow(10,dividendPrecision) / Math.pow(10,divisorPrecision)
  
  // 计算整数之商*倍率反比
  const quotNum = parseInt(intQuot.toString().replace('.', ''))
  const ratioNum = parseInt(inverseRatio.toString().replace('.', ''))
  const quotPrecision = intQuot.toString().split('.')[1]?.length || 0
  const ratioPrecision = inverseRatio.toString().split('.')[1]?.length || 0

  return (quotNum * ratioNum) / (Math.pow(10, quotPrecision) * Math.pow(10, ratioPrecision))
}

// // 测试
// divide(1.455, 0.3) 
// // 4.85
// divide(1, 0.3)
// // 3.3333333333333326

